package com.group.project.hrms.controller;

import com.group.project.hrms.utils.ProgressUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
public class ProgressController {

    /**
     * 该接口接收前端轮询请求，返回百分比
     * @param map 前端请求完成标志，S表前端数据请求已经完成，应该返回100
     * @param request http请求
     * @return 完成百分比
     */
    @RequestMapping("/basic/getPercent")
    @ResponseBody
    public int getPercent(@RequestBody Map map, HttpServletRequest request){
        Object flag = map.get("flag");
        if(null != flag){
            if(flag.toString().equals("S")){ //前端请求完成，应返回100
                ProgressUtil.percent = 0;
                return 100;
            }
            return ProgressUtil.percent;
        }else {
            return 0;
        }
    }

}
